﻿/********************************************************************************
** 作者： Mick
** 邮箱： zheng_jinfan@126.com
** 主页： http://www.zhengjinfan.cn
** 创始时间：2016-2-5
** 修改人：Mick
** 修改时间：2016-2-29
** 描述：
**      资源库只读接口
*********************************************************************************/

using System.Collections.Generic;
using BestEasyCMS.Framework.Pageing;
using BestEasyCMS.Framework.Querying;
using NPoco;
using NPoco.Linq;

namespace BestEasyCMS.Framework.Domain
{
    /// <summary>
    /// 资源库只读接口
    /// </summary>
    /// <typeparam name="T">实体对象</typeparam>
    /// <typeparam name="TId">主键类型</typeparam>
    public interface IReadOnlyRepository<T, in TId> where T : IAggregateRoot
    {
        #region Basic
        /// <summary>
        /// 获取一个对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T FindBy(TId id);
        /// <summary>
        /// 获取所有对象
        /// </summary>
        /// <returns></returns>
        IEnumerable<T> FindAll();
        /// <summary>
        /// 根据查询条件获取多个对象
        /// </summary>
        /// <param name="query">查询对象</param>
        /// <returns>结果集</returns>
        IEnumerable<T> FindBy(Query query);
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询对象</param>
        /// <param name="page"></param>
        /// <returns></returns>
        IList<T> FindBy(Query query, Paged page);
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        Page<T> FindPageBy(Query query, Paged page);
        /// <summary>
        /// 查询数据记录是否存在
        /// </summary>
        /// <typeparam name="T">实体对象类型</typeparam>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        bool Exists(TId primaryKey);
        /// <summary>
        /// 是否为新数据
        /// </summary>
        /// <param name="poco">实体</param>
        /// <returns></returns>
        bool IsNew(T poco);
        /// <summary>
        /// Linq查询
        /// </summary>
        /// <returns></returns>
        IQueryProviderWithIncludes<T> Query();
        #endregion
    }
}
